

$(function(){
	webUtils.nameSpace("wiseMen.knowledge.editing");
	
	wiseMen.knowledge.editing.add=function(grid){
		if(!!!selectCategoryId || selectCategoryId=='-1'){
			webUtils.alert("请选择一个知识类别！！");
			return;
		}
		var uuid=webUtils.uuid();
		var d=webUtils.dialog({
			url:ctx+"/dataModelDefAct/editTpl.do?dms=KBMS_INFO&winId="+uuid+"&KBMS_INFO_CATEGORYID="+selectCategoryId+"&KBMS_INFO_STATE=0&KBMS_INFO_VERSION=1.0",
			onremove:function(){
				webUtils.topicPublish("dialog.close."+uuid,{uuid:uuid});
			}
		});
		webUtils.topicSubscribe("dialog.submit.success."+uuid,function(data){
			grid.bootstrapTable("refresh");
			d.close();
		},true);
	}
	
	wiseMen.knowledge.editing.mod=function(grid,rowIndex){
		var row = grid.bootstrapTable("getRowByIndex", rowIndex);
		var uuid=webUtils.uuid();
		var d=webUtils.dialog({
			url:ctx+"/dataModelDefAct/editTpl.do?dms=KBMS_INFO&KBMS_INFO_ID="+row.ID+"&winId="+uuid+"&KBMS_INFO_STATE=0",
			onremove:function(){
				webUtils.topicPublish("dialog.close."+uuid,{uuid:uuid});
			}
		});
		webUtils.topicSubscribe("dialog.submit.success."+uuid,function(data){
			grid.bootstrapTable("refresh");
			d.close();
		},true);
	}
	
	wiseMen.knowledge.editing.del=function(grid,rowIndex){
		var row = grid.bootstrapTable("getRowByIndex", rowIndex);
		webUtils.confirm("删除数据将不可恢复，是否继续！",function(r){
			if(r){
				$.post(ctx + "/formDataAction/delByIds.do", {tableName:"KBMS_INFO",ids: row.ID}, function (data) {
	                if (data.success) {
	                	grid.bootstrapTable("refresh");
	                } else {
	                	webUtils.error(data.msg);
	                }
	            }, 'json');
			}
		});
	}
	//送审核
	wiseMen.knowledge.editing.audit=function(grid){
		var selections =grid.bootstrapTable("getSelections");
		if(selections.length==0){
			webUtils.alert("请至少选择一条记录！！");
			return;
		}
		webUtils.confirm("确定把选中知识送审核吗？",function(r){
			if(r){
				var ids=[];
				for(var i=0; i<selections.length; i++){
					ids.push(selections[i]['ID']);
				}
				$.post(ctx + "/KBMS/edit/pass.do",{
					ids:ids.join(',')
				},function(data){
					webUtils.alert(data.msg);
					if(data.success){
						grid.bootstrapTable("refresh");
					}
				},'json');
			}
		});
	}
	
	wiseMen.knowledge.editing.recovery=function(grid){
		var selections =grid.bootstrapTable("getSelections");
		if(selections.length==0){
			webUtils.alert("请至少选择一条记录！！");
			return;
		}
		webUtils.prompt("请填写撤回原因",function(value){
			var ids=[];
			for(var i=0; i<selections.length; i++){
				ids.push(selections[i]['ID']);
			}
			$.post(ctx + "/KBMS/edit/recovery.do",{
				ids:ids.join(','),
				operatExplain:value
			},function(data){
				webUtils.alert(data.msg);
				if(data.success){
					grid.bootstrapTable("refresh");
				}
			},'json');
		});
	}
	
	wiseMen.knowledge.editing.perview=function(grid,rowIndex){
		var row = grid.bootstrapTable("getRowByIndex", rowIndex);
		var uuid=webUtils.uuid();
		var d=webUtils.dialog({
			url:ctx+"/KBMS/issue/perviewInfo.do?id="+row.ID+"&winId="+uuid,
			onremove:function(){
				webUtils.topicPublish("dialog.close."+uuid,{uuid:uuid});
			}
		});
	}
});